package com.dream.inspect.modules.business.controller;

import com.dream.inspect.common.utils.PageUtils;
import com.dream.inspect.common.utils.R;
import com.dream.inspect.common.validator.ValidatorUtils;
import com.dream.inspect.modules.business.entity.MessageOnOffEntity;
import com.dream.inspect.modules.business.service.MessageOnOffService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.Map;



/**
 * 短信开启设置表
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2018-06-16 17:04:50
 */
@RestController
@RequestMapping("business/messageonoff")
public class MessageOnOffController {
    @Autowired
    private MessageOnOffService messageOnOffService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("business:messageonoff:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = messageOnOffService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("business:messageonoff:info")
    public R info(@PathVariable("id") Long id){
        MessageOnOffEntity messageOnOff = messageOnOffService.selectById(id);

        return R.ok().put("messageOnOff", messageOnOff);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("business:messageonoff:save")
    public R save(@RequestBody MessageOnOffEntity messageOnOff){
        messageOnOffService.insert(messageOnOff);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("business:messageonoff:update")
    public R update(@RequestBody MessageOnOffEntity messageOnOff){
        ValidatorUtils.validateEntity(messageOnOff);
        messageOnOffService.updateAllColumnById(messageOnOff);//全部更新
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("business:messageonoff:delete")
    public R delete(@RequestBody Long[] ids){
        messageOnOffService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
